package com.ballgame;
import java.awt.*;
//游戏物体的根类
public class GameObject {
        Image img;//对应的图片
        int x,y;//坐标
        int speed;//物体移动
        int width,height;//物体的宽度和高度
    //画自己
    public void drawMySelf(Graphics g){
        g.drawImage(img,x,y,width,height,null);
    }
    //返回该物体的矩形，因为物体都是矩形
    public Rectangle getRec(){ //Rectangle 意思是矩形
        return new Rectangle(x,y,width,height);
    }

    //构造器
    public GameObject (){}
    //当全部属性都有
    public GameObject(Image img, int x, int y, int speed, int width, int height) {
        this.img = img;
        this.x = x;
        this.y = y;
        this.speed = speed;
        this.width = width;
        this.height = height;
    }
    //只有速度
    public GameObject(Image img, int x, int y, int speed) {
        this(img,x,y);//调用下面的构造器

        this.speed = speed;
    }
    //只有x,y
    public GameObject(Image img,int x, int y) {
        this(img);
        this.x = x;
        this.y = y;
    }

    //当只有img
    public GameObject(Image img) {
        this.img = img;
         //当物体没有指宽高时，图片有宽高，就传入物体的宽高
        if(this.img!=null){
            this.width = img.getWidth(null);
            this.height = img.getHeight(null);
        }



    }
}
